package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.LogininfoBean;
import cn.xfdzx.android.apps.shop.contract.FeedBackContract;
import cn.xfdzx.android.apps.shop.contract.PassWordLoginContract;
import cn.xfdzx.android.apps.shop.model.FeedBackModel;
import cn.xfdzx.android.apps.shop.model.PassWordLoginModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class PassWordLoginPresenter extends BasePresenter<PassWordLoginContract.View> implements PassWordLoginContract.Presenter {

    private PassWordLoginContract.Model model;

    public PassWordLoginPresenter() {
        model = new PassWordLoginModel();
    }




    @Override
    public void passWordLogin(String mobile, String pwd) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.passWordLogin(mobile, pwd)
                .compose(RxScheduler.<LogininfoBean>Flo_io_main())
                .as(mView.<LogininfoBean>bindAutoDispose())
                .subscribe(new Consumer<LogininfoBean>() {
                    @Override
                    public void accept(LogininfoBean bean) throws Exception {
                        mView.onPassWordLoginSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
